
<?php session_start();

if (empty($_SESSION['nombre']))
	echo "<meta http-equiv='Refresh' content='0;url=../index.php'>";
if (empty($_REQUEST['cliente']))
	echo "<meta http-equiv='Refresh' content='0;url=../index.php'>";
require '../../config.php';

$registros=mysql_query("select nombre from  clientesventas where idclientesventas='".$_REQUEST['cliente']."' limit 1");
if (mysql_num_rows($registros) > 0)

{
	$data = array();
	
	$row = mysql_fetch_array($registros);

		$data[] = $_REQUEST['cliente'];//0
		$data[] = _convert($row['nombre']);
		mysql_close();
	
}
function _convert($content) {
		if(!mb_check_encoding($content, 'UTF-8')
		OR !($content === mb_convert_encoding(mb_convert_encoding($content, 'UTF-32', 'UTF-8' ), 'UTF-8', 'UTF-32'))) {
	
			$content = mb_convert_encoding($content, 'UTF-8');
	
			if (mb_check_encoding($content, 'UTF-8')) {
				// log('Converted to UTF-8');
			} else {
				// log('Could not converted to UTF-8');
			}
		}
		return $content;
	}
?>
<!DOCTYPE html>
<head>
<title>Formulario de Pago</title>

</head>
<script type="text/javascript">
		$(document).ready(function()
		{
		   var jQueryDatePicker1Opts =
		   {
		      dateFormat: 'yy-mm-dd',
		      changeMonth: false,
		      changeYear: false,
		      showButtonPanel: false,
		      showAnim: 'show'
		   };
		   $("#fechaprox222").datepicker(jQueryDatePicker1Opts);
		  
		  
		});
</script>
<body id="main_body" >

<div style="background-color:blue; height:3px;"></div>
	<img id="top" src="../../imagenes/top.png" alt="">
	<div id="form_container"  style="background-color: #f2f9f2" >
		<h1><a style="background-color: #00f"></a></h1>
		
		<form id="formulario" name="formulario"  style="background-color: #f2f9f2" >
					<div class="form_description">
			<h2>Formulario Registro de Pago</h2>
			<p><strong>Datos del Cliente:</strong></p>
		</div>						
			<ul >
		
			
		<li  >
		<label class="description" for="nombrecliente">Nombre de cliente o empresa: </label>
		<div>
			<input id="nombrecliente" value="<?php echo $data[1];?>" disabled name="element_44d" class="element text medium" type="text" maxlength="30" size="30">
		</div> 
		
		</li>
		<li>
		<?php 
		echo "<div>";
				echo "<label class='description' for='telefonover'>N&uacute;mero de Contrato: </label>";
				echo "<select id='conts2' onchange='cambiarContrato2();'>";
				echo "<option value='0' selected>Seleccione el Contrato</option>";
				$query2="SELECT idcontratos FROM hossbd.contratos where activo=1 and cliente = ".$data[0];
				$result2 = mysql_query($query2,$conexion);
				if(mysql_num_rows($result2)>0)
				{
					while($row2 = mysql_fetch_assoc($result2))
					{
						
							echo "<option value=".$row2['idcontratos'].">".$row2['idcontratos']."</option>";
						
					}
						
				}
				echo "</select>";
				echo "</div>";
		?>
		</li>
		<li  ><legend>Descripci&oacute;n del Contrato:</legend>
			
		</li>
			<li>
			<div id="desccont">
			
			</div>
			</li>
			<li>
			<?php 
			echo 	"<div>";
			echo 	"<label class='description' for='profesionver'>Monto a Pagar: </label>";
			echo 	"<input id='monto222' required type='text'  size='10' onkeyUp='return ValNumero(this);'>";
			echo 	"</div>";
			?>
			</li>
			
			<li><div>
			
			<label class="description" for="element_722">Pr&oacute;xima Fecha de Pago: </label>
			<input id="fechaprox222" name="element_722" title="Opcional" class="element text medium" maxlength="250" value="" type="text">
		</div>
			</li>
			<li><div>
			
			<label class="description" for="element_722">Observaci&oacute;n: </label>
			<input id="obs222" name="element_722" title="Opcional" class="element text medium" maxlength="250" value="" type="text">
		</div>
			</li>										
		<legend></legend>
		<li class="buttons">
		<input id="enviar" class="btn btn-success" type="button"  value="Registrar Pago" onclick="registarPago();" />
		<input id="cancelar" class="btn btn-warning" type="button" name="cancelar" value="Cancelar" onclick="regresar22();" />
		</li>
			</ul>
		</form>	
		
	</div>
	<img id="bottom" src="../../imagenes/bottom.png" alt="">
	<!--  footer -->
   <img id="bottom" src="../../imagenes/top.png" alt="">
    <img id="bottom" src="../../imagenes/bottom.png" alt="">
   
	</body>
	
<script type="text/javascript">
var codcli22 = "<?php echo $data[0]; ?>";
function registarPago()

{
	try {
		
	
	   
		var contrato = document.getElementById('conts2').value;
		
		var fechaprox = document.getElementById('fechaprox222').value;
		var monto = document.getElementById('monto222').value;
		var observacion = document.getElementById('obs222').value;
		

		if(monto <= 0){ alertar("El Monto no puede ser Cero","warning");return;}
		if(contrato == "0"){ alertar("Primero, Seleccione un Contrato","warning");return;}
		
		var saldo = document.getElementById('saldoactual').value;
		saldo = parseFloat(saldo);
		monto = parseFloat(monto);
		if(saldo <= 0){ alertar("El Saldo Actual del Cliente es de Cero o Menos.","warning");return;}
		if(monto > saldo)monto = saldo;
	
		if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
    	else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		 xmlhttp.onreadystatechange = presentarReportePago;
    xmlhttp.open("GET","regpago.php?idcontrato="+contrato+"&fechaprox="+fechaprox+"&monto="+monto+"&observacion="+observacion, false);
    xmlhttp.send();
	
	/* var hostInfo="";
    hostInfo = xmlhttp.responseText;
   
	  if(hostInfo == "ok")
	{
	 	
		
		 ver2(codcli22);
	}
	else
	{
		alertar(hostInfo,"danger");
		ver2(codcli22);
	}  */
		  
	}catch (err) {
		alertar("Error JS= " + err.message, "error");
	}	
		
	}
	var xmlhttp;
function presentarReportePago()
{
  
	
  if(xmlhttp.readyState == 4)
  {
	  hostInfo = xmlhttp.responseText;
	   
	  if(hostInfo == "ok")
	{
	 	
		
		 ver2(codcli22);
		 
	}
	else
	{
	 alertar(xmlhttp.responseText,"error");
	} 
  }
 
	  
	 
}
function regresar22() {
	try {
		ver2(codcli22);
	} catch (e) {
		alertar(e.message,"error");
	}
	
}


</script>

</html>
